package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.CompanyAdditionalFieldsAddDTO;
import org.jsola.hr.dto.CompanyAdditionalFieldsUpdateDTO;
import org.jsola.hr.entity.CompanyAdditionalFieldsDO;
import org.jsola.hr.query.CompanyAdditionalFieldsQuery;
import org.jsola.hr.service.ICompanyAdditionalFieldsService;
import org.jsola.hr.vo.CompanyAdditionalFieldsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 公司员工额外字段表
 *
 * @author zhr
 */
@Component
public class CompanyAdditionalFieldsTestHelper extends BaseTestHelper {
    
    @Autowired
    private ICompanyAdditionalFieldsService companyAdditionalFieldsService;

    /**
     * 生成add测试数据
     * @return CompanyAdditionalFieldsAddDTO
     */
    public CompanyAdditionalFieldsAddDTO getCompanyAdditionalFieldsAddDTO(){
        CompanyAdditionalFieldsAddDTO companyAdditionalFieldsAddDTO = new CompanyAdditionalFieldsAddDTO();
        companyAdditionalFieldsAddDTO.setTextLength(SafeKit.getInteger(getRandomValue("int",10)));
        companyAdditionalFieldsAddDTO.setDescription(getRandomValue("varchar",50));
        companyAdditionalFieldsAddDTO.setIsEdit(SafeKit.getInteger(getRandomValue("int",2)));
        companyAdditionalFieldsAddDTO.setModuleCode(getRandomValue("varchar",30));
        companyAdditionalFieldsAddDTO.setModuleType(getRandomValue("varchar",32));
        companyAdditionalFieldsAddDTO.setFieldType(SafeKit.getInteger(getRandomValue("int",1)));
        companyAdditionalFieldsAddDTO.setFieldName(getRandomValue("varchar",50));
        companyAdditionalFieldsAddDTO.setCompanyId(getRandomValue("varchar",32));
        companyAdditionalFieldsAddDTO.setOptions(getRandomValue("text",2147483647));
        companyAdditionalFieldsAddDTO.setSort(SafeKit.getInteger(getRandomValue("int",11)));
        companyAdditionalFieldsAddDTO.setIsNecessary(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        companyAdditionalFieldsAddDTO.setIsOpen(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        companyAdditionalFieldsAddDTO.setTemplateId(getRandomValue("varchar",32));
        companyAdditionalFieldsAddDTO.setSourceId(SafeKit.getLong(getRandomValue("bigint",11)));
        return companyAdditionalFieldsAddDTO;
    }


    /**
     * 生成update测试数据
     * @return CompanyAdditionalFieldsUpdateDTO
     */
    public CompanyAdditionalFieldsUpdateDTO getCompanyAdditionalFieldsUpdateDTO(CompanyAdditionalFieldsVO companyAdditionalFieldsVO){
        return companyAdditionalFieldsService.selectDOById(companyAdditionalFieldsVO.getId(), SITE_ID).to(CompanyAdditionalFieldsUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return CompanyAdditionalFieldsQuery
     */
    public CompanyAdditionalFieldsQuery getCompanyAdditionalFieldsQuery() {
        CompanyAdditionalFieldsQuery companyAdditionalFieldsQuery = new CompanyAdditionalFieldsQuery();
        List<CompanyAdditionalFieldsDO> companyAdditionalFieldsDOList = companyAdditionalFieldsService.list(new CompanyAdditionalFieldsDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(companyAdditionalFieldsDOList)) {
            CompanyAdditionalFieldsDO companyAdditionalFieldsDO = companyAdditionalFieldsDOList.get(0);
            companyAdditionalFieldsQuery = companyAdditionalFieldsDO.to(CompanyAdditionalFieldsQuery.class);
        }
        return companyAdditionalFieldsQuery;
    }

    /**
     * 保存示例
     * @return CompanyAdditionalFieldsVO
     */
    public CompanyAdditionalFieldsVO saveCompanyAdditionalFieldsExample(){
        CompanyAdditionalFieldsAddDTO addDTO = this.getCompanyAdditionalFieldsAddDTO();
        CompanyAdditionalFieldsVO companyAdditionalFieldsVO = companyAdditionalFieldsService.save(addDTO,buildTokenUser());
        return companyAdditionalFieldsVO;
    }


}

